const jokeE1 = document.getElementById('joke')
const jokeBtn = document.getElementById('jokeBtn')

jokeBtn.addEventListener('click', generateJoke)

generateJoke()

async function generateJoke() {
    const config = {
        headers: {
            Accept: 'application/json'
        }
    }

    const res = await fetch('https://icanhazdadjoke.com', config)

   
    console.log({ res });
     //把响应数据转为json
    const data = await res.json()

    console.log({ data });
    jokeE1.innerHTML = data.joke
}


// function generateJoke() {
//     const config = {
//         headers: {
//             Accept: 'application/json'
//         }
//     }

//     fetch('https://icanhazdadjoke.com', config)
//         .then(res => res.json())
//         .then(data => {
//             jokeE1.innerHTML = data.joke
//         })
// }

